package com.ytzl.itrip.service.impl;

import com.ytzl.itrip.dao.ItripOrderLinkUserMapper;
import com.ytzl.itrip.service.ItripOrderLinkUserService;
import com.ytzl.itrip.pojo.ItripOrderLinkUser;
import com.ytzl.itrip.common.EmptyUtils;
import com.ytzl.itrip.common.Constants;
import com.ytzl.itrip.common.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ItripOrderLinkUserServiceImpl implements ItripOrderLinkUserService {

    @Resource
    private ItripOrderLinkUserMapper itripOrderLinkUserMapper;

    public ItripOrderLinkUser getItripOrderLinkUserById(Long id) throws Exception {
        return itripOrderLinkUserMapper.getItripOrderLinkUserById(id);
    }

    public Integer removeItripOrderLinkUserById(Long id) throws Exception {
        return itripOrderLinkUserMapper.removeItripOrderLinkUserById(id);
    }

    public List<ItripOrderLinkUser> getItripOrderLinkUserListByMap(Map
                                                                           <String, Object> param) throws Exception {
        List<ItripOrderLinkUser> list = itripOrderLinkUserMapper.getItripOrderLinkUserListByMap(param);
        return list;
    }

    public Integer getItripOrderLinkUserCountByMap(Map
                                                           <String, Object> param) throws Exception {
        return itripOrderLinkUserMapper.getItripOrderLinkUserCountByMap(param);
    }

    public Integer saveItripOrderLinkUser(ItripOrderLinkUser itripOrderLinkUser) throws Exception {
        itripOrderLinkUser.setCreationDate(new Date());
        return itripOrderLinkUserMapper.saveItripOrderLinkUser(itripOrderLinkUser);
    }

    public Integer modifyItripOrderLinkUser(ItripOrderLinkUser itripOrderLinkUser) throws Exception {
        itripOrderLinkUser.setModifyDate(new Date());
        return itripOrderLinkUserMapper.modifyItripOrderLinkUser(itripOrderLinkUser);
    }

    public Integer removeItripOrderLinkUserByIds(Long[] ids) throws Exception {
        return itripOrderLinkUserMapper.removeItripOrderLinkUserByIds(ids);
    }

    @Override
    public List<Long> getItripOrderLinkUserIdsByOrder() {
        return itripOrderLinkUserMapper.getItripOrderLinkUserIdsByOrder();
    }

    public Page<ItripOrderLinkUser> queryItripOrderLinkUserPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = itripOrderLinkUserMapper.getItripOrderLinkUserCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ItripOrderLinkUser> itripOrderLinkUserList = itripOrderLinkUserMapper.getItripOrderLinkUserListByMap(param);
        page.setRows(itripOrderLinkUserList);
        return page;
    }

}
